package xby.study.proxy.cglib.dispatcher;

import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Dispatcher;
import net.sf.cglib.proxy.Enhancer;
import xby.study.proxy.cglib.PathUtil;


public class DispatcherTest {
    public void test() {
        System.out.println(this.getClass().getName());
    }

    public static void main(String[] args) {
        // 配置class文件的输出目录
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, PathUtil.getOutPath(DispatcherTest.class));

        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(DispatcherTest.class);
        enhancer.setCallback((Dispatcher) SonDispatcherTest::new);
        DispatcherTest test = (DispatcherTest) enhancer.create();
        test.test();
    }
}


class SonDispatcherTest extends DispatcherTest {
    public void test() {
        System.out.println("before method ...");
        System.out.println(this.getClass().getName());
        System.out.println("before method ...");
    }
}
